<?php
class Wishlist extends MY_Model{
    public function __construct() {
        parent::__construct();
    }
    
    public function addWishlist($feild =array()){
        if(!is_array($feild)) return false;
        $this->db->where('user_id',$this->tank_auth->get_user_id());
        $this->db->where('product_id',$feild['product_id']);
        $this->db->select('wl_id');
        $this->db->from('wishlist');
        $row = $this->db->get()->row();
        if(empty($row)){
            $query = $this->db->insert('wishlist',$feild);
            return $this->db->affected_rows();    
        }
    }
    public function updateWishlist($feild=array()){
        if(!is_array($feild)) return false;
        $this->db->where('wl_id',$feild['wl_id']);
        $this->db->update('wishlist',$feild);
        return $this->db->affected_rows();
    }
    public function deleteWishlist($wl_id = false,$user_id=false){
        if($wl_id)
            $this->db->where('wl_id',$wl_id);
        if($user_id)
            $this->db->where('user_id',$user_id);
        $this->db->delete('wishlist');
        return $this->db->affected_rows();
    }
    public function getWishlish($user_id = false){
        if(!$user_id) return false;
        $this->db->where('user_id',$user_id);
        $query = $this->db->get('wishlist');
        if($query->num_rows()==1)
            return $query->row();
        elseif($query>1)
            return $query->result();
        else
            return false;
    }
}